﻿using System;
using System.Collections.Generic;
using System.Text;
using Gtk;

namespace GtkSharpTutorial
{
    class Form
    {
        public event DeleteEventHandler DeleteEvent;

        Window window;
        static HScale hscale;
        static VScale vscale;

        static void cb_pos_menu_select(object obj, PositionType pos)
        {
            /* Set the value position on both scale widgets */
            ((Scale)hscale).ValuePos = pos;
            ((Scale)vscale).ValuePos = pos;
        }


        //static void cb_update_menu_select(object obj, UpdateType policy)
        //{
        //    /* Set the update policy for both scale widgets */
        //    ((Range)hscale).UpdatePolicy = policy;
        //    ((Range)vscale).UpdatePolicy = policy;
        //}


        static void cb_digits_scale(Adjustment adj)
        {
            /* Set the number of decimal places to which adj->value is rounded */

            /* FIXME: this might be wrong */
            // ((Scale) hscale) = adj.Value;
            // ((Scale) vscale) = adj.Value;
        }


        // FIXME
        static void cb_page_size(Adjustment get, Adjustment set)
        {
            /* Set the page size and page increment size of the sample
             * adjustment to the value specified by the "Page Size" scale */
            //set.PageSize = get.Value;
            //set->page_increment = = get.Value;

            /* This sets the adjustment and makes it emit the "changed" signal to
               reconfigure all the widgets that are attached to this signal.  */
            //set.ClampPage (
        }

        // FIXME
        static void cb_draw_value(ToggleButton button)
        {
            /* Turn the value display on the scale widgets off or on depending
             *  on the state of the checkbutton */
            //((Scale) hscale).DrawValue  button.Active
            //((Scale) vscale).DrawValue  button.Active
        }


        /* Convenience functions */

        // FIXME:
        static Widget make_menu_item(string name /*, callback , gpointer */)
        {
            Widget w = null;
            return w;
        }


        static void scale_set_default_values(Scale s)
        {
            //s.UpdatePolicy = UpdateType.Continuous;
            s.Digits = 1;
            s.ValuePos = PositionType.Top;
            s.DrawValue = true;
        }

        public void Show()
        {
            Button button;
            HSeparator separator;
            Label label;
            Scale scale;
            Adjustment adj2;

            window = new Window(WindowType.Toplevel);
            window.Title = "range controls";
            window.DeleteEvent += (s, e) => DeleteEvent?.Invoke(s, e);

            var box1 = new VBox(false, 0);
            window.Add(box1);
            box1.ShowAll();

            var shareAdjument = new ShareAdjument();
            box1.PackStart(shareAdjument.Widget, true, true, 0);


            var box9 = new HBox(false, 10);
            box9.BorderWidth = 10;

            /* An HScale widget for adjusting the number of digits on the
             * sample scales. */
            label = new Label("Scale Digits:");
            box9.PackStart(label, false, false, 0);
            label.ShowAll();

            adj2 = new Adjustment(1.0, 0.0, 5.0, 1.0, 1.0, 0.0);
            //FIXME: add a value_changed signal handler
            scale = new HScale(adj2);
            scale.Digits = 0;

            box9.PackStart(scale, true, true, 0);
            scale.ShowAll();

            box1.PackStart(box9, true, true, 0);
            box9.ShowAll();

            var box10 = new HBox(false, 10);
            box10.BorderWidth = 10;

            /* And, one last HScale widget for adjusting the page size of the
             * scrollbar. */
            label = new Label("Scrollbar Page Size:");
            box10.PackStart(label, false, false, 0);
            label.ShowAll();

            adj2 = new Adjustment(1.0, 1.0, 101.0, 1.0, 1.0, 0.0);
            // FIXME: write a value_changed signal handler
            scale = new HScale(adj2);
            scale.Digits = 0;
            box10.PackStart(scale, true, true, 0);
            scale.ShowAll();

            box1.PackStart(box10, true, true, 0);
            box10.ShowAll();

            separator = new HSeparator();
            box1.PackStart(separator, false, true, 0);
            separator.ShowAll();

            var box5 = new VBox(false, 10);
            box5.BorderWidth = 10;
            box1.PackStart(box5, false, true, 0);
            box5.ShowAll();

            button = new Button("Quit");
            // FIXME: write a clicked signal handler
            box5.PackStart(button, true, true, 0);
            //FIXME: set widget flags
            //FIXME: grab default
            button.ShowAll();

            window.ShowAll();
        }
    }
}
